import user from "@/core/models/user";
export default {
    namespaced: true,
    state: {
        showLoginModal: false,
        openId: "",
        token: "",
        finishInfo: false,
        info: {
            nickname: "",
            openid: "",
            mobile: "",
            createTime: 0,
            worker: {},
            serviceData: {
                times: 0,
                favorableRate: "0",
                grade: "0",
                disposableBalance: 0,
                FreezeBalance: 0,
            },
        },
    },
    getters: {
        isLogin(state) {
            return state.token && state.token.length > 0;
        },
        acceptOrder(state) {
            return state.info.worker.acceptOrderState == 1;
        },
    },
    mutations: {
        showLoginModal(state, data) {
            state.showLoginModal = data;
        },
        openId(state, data) {
            state.openId = data;
        },
        token(state, data) {
            state.token = data;
        },
        info(state, data) {
            state.info = data;
        },
        finishInfo(state, data) {
            state.finishInfo = data;
        }
    },
    actions: {
        async info(context, refresh) {
            await user.info(refresh).then(info => {
                if (info.worker != null) {
                    context.commit('finishInfo', true);
                }
                context.commit('info', info);
            });
        },
        logout(context) {
            context.commit('info', null);
        },
    }
}
